package com.example.rss_reder;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class DBAdapter{
	private DBHelper helper;
	private SQLiteDatabase db;
	private final Context con;
	private final String DBName = "my_news";
	
	public DBAdapter(Context con){
		this.con = con;
	}
	
	public DBAdapter open() throws SQLException{
		helper = new DBHelper(con);
		db = helper.getWritableDatabase();
	
		return this;
	}
	
	public void close(){
		helper.close();
	}
	
	public void inser(String name, String date, String img, String link){

	    ContentValues row = new ContentValues();
			row.put("name", name);
			row.put("date", date);
			row.put("img", img);
			row.put("link", img);
			
			db.insert(DBName, null, row);
		}
	
	public boolean delete(int _id){
		return db.delete(DBName, "_id = " + _id, null) > 0;
	}
	
	public Cursor cursor(String sql){
		return db.rawQuery(sql, null);
	}
	
}
